package cn.thoughtworks.school.programCenter.feign;

import cn.thoughtworks.school.programCenter.entities.UserRole;
import cn.thoughtworks.school.programCenter.entities.commands.CreateUserOrganization;
import cn.thoughtworks.school.programCenter.entities.dto.UserDto;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@FeignClient(name = "${feign.userCenter.name}",
        url = "${feign.userCenter.url}")
@Service
public interface UserCenterFeign {
    @GetMapping("api/users/ids/{ids}")
    ResponseEntity<List<Map>> getUsersByIds(@PathVariable("ids") String ids);

    @GetMapping("api/users/{userId}")
    ResponseEntity<Map> getUserById(@PathVariable("userId") Long userId);

    @GetMapping("api/users/username")
    ResponseEntity<Map> getUserByUsername(@RequestParam("username") String username);

    @GetMapping("api/users")
    ResponseEntity<List<Map>> getUserByUserNameOrEmail(@RequestParam("nameOrEmail") String nameOrEmail);

    @PostMapping("api/users/roles")
    ResponseEntity addRole(@RequestBody Map data);

    @PostMapping("api/users/searches")
    ResponseEntity<List<Map>> searchUsersByConditions(@RequestBody Map searchParam);

    @DeleteMapping("api/organizations/{organizationId}/users/{userId}/roles")
    ResponseEntity deleteUserRole(@PathVariable("organizationId") Long organizationId,
                                  @PathVariable("userId") Long userId,
                                  @RequestParam("roleNumber") Integer roleNumber);

    @PostMapping("api/users/{userId}/roles")
    ResponseEntity addUserRole(@RequestBody Map userRole);

    @GetMapping("api/organizations/{organizationId}/users/roles")
    List<Map> getUserRolesByOrganizationId(@PathVariable("organizationId") Long organizationId);

    @PostMapping("api/organizations/{organizationId}/users/searches")
    List<Map> searchUsersByConditionsAndOrganizationId(@PathVariable("organizationId") Long organizationId,
                                                            @RequestBody Map condition);

    @GetMapping("api/organizations/{organizationId}/users/ids/{ids}")
    List<UserRole> getUsersByOrganizationIdAndIds(@PathVariable("organizationId") Long organizationId,
                                             @PathVariable("ids") String ids);

    @PutMapping("api/users/organizations")
    void updateUserCurrentOrganizationId(@RequestBody CreateUserOrganization createUserOrganization);

    @GetMapping("api/users/{userId}/roles")
    List<Map> findUserRolesByUserId(@PathVariable("userId") Long userId);

    @GetMapping("api/users/import")
    void importUsers(@RequestBody  List<UserDto> userDtos);
}
